package Entity;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.sql.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import ServerOperation.ReportPDFWriter;

import com.itextpdf.text.Document;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.ColumnText;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfImportedPage;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import com.itextpdf.text.pdf.PdfWriter;

import Controllers.GlobalData;
import Controllers.GenericToolsForController.PDFDocument;
import Controllers.GenericToolsForController.PDFfile;

public class EvaluationReport extends Report {
	Worker creator;	 //override reports user

    
	
    
	
	public EvaluationReport(Request request, String strLocation, String strDescription,
			String strDesiredChange, String strRisk, int daysEstimate) throws IOException 
	{
	    
		String strDateHeadline = "Generated On: ";
	      String strLocationHeadline = "Location of the proposed change:";
	      String strDescriptionHeadlin = "Description of the proposed change:";
	      String strProposedChangeHeadline = "Desired Change: " ;
	      String strRisksHeadline = "Risks and Limitations: ";
	      String strEstimatedTimeHeadline = "Estimated Time for completion: ";
		this.type = ReportType.EVALUATION;
		this.setCreator(GlobalData.worker);
		this.dateOfCreation = Calendar.getInstance().getTime();
		
		 String strHeadline = "Evaluation Report for Evaluator: ";
	     String strHeadlineReval = "Re-Evaluation (More details needed) Report for Evaluator: ";
	     String currentDir = System.getProperty("user.dir");
			String path = currentDir+"\\";
			File dir=new File(path);
			if(! dir.exists())
			{
				dir.mkdir();
				System.out.println("Creats new dir : "+path);
			}
			path = (path + (this.creator.getUsername().replaceAll(" ", "_").replaceAll(":", "_"))+"\\");
			 dir=new File(path);
			if(! dir.exists())
			{
				dir.mkdir();
				System.out.println("Creats new dir : "+path);
			}
			path = path +creator.getId()+"\\";
			 dir=new File(path);

			if(! dir.exists())
			{
				dir.mkdir();
				System.out.println("Creats new dir : "+path);
			}
			path = path +request.getRequestId()+"\\";
			 dir=new File(path);

			if(! dir.exists())
			{
				dir.mkdir();
				System.out.println("Creats new dir : "+path);
			}
			String startDateOfCreation = new SimpleDateFormat("yyyy-MM-dd").format(dateOfCreation);
			path+="EvaluationReport-"+startDateOfCreation+".pdf";
			
			ReportPDFWriter writer = new ReportPDFWriter(path);
			writer.addLogo();
		/*	if (this.notes != null)	
			{
				writer.writeTitle("Evaluation Report appends:");
		  	    writer.writeUnderline(strHeadlineReval);
		  	    writer.write(creator.toString()+"\n\n");
			    writer.writeUnderline("The evlautor added the following details: "+"\n\n");
				writer.write(notes+ " \n\n");
				writer.writeTitle("Prevoius reports: \n\n");
				notes = null;
			}*/
				writer.writeUnderline(strHeadline);
				writer.write(creator.toString()+"\n\n");
				writer.writeUnderline(strDateHeadline);
				writer.write(startDateOfCreation+"\n" );
				writer.writeUnderline(strLocationHeadline);
				writer.write(strLocation+"\n\n");
				writer.writeUnderline(strDescriptionHeadlin);
				writer.write(strDescription+"\n\n");
				writer.writeUnderline(strProposedChangeHeadline);
				writer.write(strDesiredChange+"\n\n");
				writer.writeUnderline(strRisksHeadline);
				writer.write(strRisk+"\n");
				writer.writeUnderline(strEstimatedTimeHeadline);
				writer.write(daysEstimate+"  days\n\n");            
			    writer.close();
			     pdfFile = new PDFfile(path)   ;
	      
	}	
	
	
	

public Worker getCreator() {
	return creator;
}
public void setCreator(Worker creator) {
	this.creator = creator;
}

}